package com.lvmama.rhino.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lvmama.rhino.entity.MessageStatisticalVO;
import com.lvmama.rhino.entity.MessageVO;
import com.lvmama.rhino.enums.CommonStringType;
import com.lvmama.rhino.mapperHippo.MessageMapper;
import com.lvmama.rhino.pojo.Message;
import com.lvmama.rhino.pojo.MessageStatistical;
import com.lvmama.rhino.service.MessageService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("messageService")
public class MessageServiceImpl implements MessageService {

    /**
     * 日志
     */
    protected Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private MessageMapper messageMapper;

    /**
     * 根据条件查询消息回执的信息
     *
     * @param messageVO
     */
    @Override
    public PageInfo<Message> getMessageListPage(MessageVO messageVO) {
        PageHelper.startPage(messageVO.getPage(), messageVO.getPageSize());
        List<Message> messages = messageMapper.getMessageListPage(messageVO);
        logger.info("根据条件查询消息回执的信息messages=" + messages);
        PageInfo<Message> page = new PageInfo<Message>(messages);
        return page;
    }


    /**
     * 查询时段中各类别下的消息回执的数量
     *
     * @param i 当前日期向前移动天数
     * @param j 当前日期向前移动天数
     * @return
     */
    @Override
    public List<Message> selectDateCategoryCount(int i, int j) {
        return messageMapper.selectDateCategoryCount(i, j);
    }


    /**
     * 根据条件查询推送消息的推送量，送达量和点击量
     *
     * @param messageStatisticalVO
     * @return
     */
    @Override
    public PageInfo<MessageStatistical> getMessageStatisticalList(MessageStatisticalVO messageStatisticalVO) {
        PageHelper.startPage(messageStatisticalVO.getPage(), messageStatisticalVO.getPageSize());
        String pushCategory = messageStatisticalVO.getPushCategoryStatisticalVO();
        List<MessageStatistical> messageStatistical = null;
        if (pushCategory.equals(CommonStringType.NORMAL.getValue()) || pushCategory.equals(CommonStringType.MEMBER_MODEL.getValue()) || pushCategory.equals(CommonStringType.PERSONALISE.getValue())) {
            messageStatistical = messageMapper.getActivityMessageStatisticalList(messageStatisticalVO);
        } else {
            messageStatistical = messageMapper.getMessageStatisticalList(messageStatisticalVO);
        }
        PageInfo<MessageStatistical> page = new PageInfo<MessageStatistical>(messageStatistical);
        return page;
    }


    /**
     * 导出推送消息统计
     *
     * @param messageStatisticalVO
     * @return
     */
    @Override
    public List<MessageStatistical> exportStatistical(MessageStatisticalVO messageStatisticalVO) {
        String pushCategory = messageStatisticalVO.getPushCategoryStatisticalVO();
        List<MessageStatistical> messageStatistical = null;
        if (pushCategory.equals(CommonStringType.NORMAL.getValue()) || pushCategory.equals(CommonStringType.MEMBER_MODEL.getValue()) || pushCategory.equals(CommonStringType.PERSONALISE.getValue())) {
            messageStatistical = messageMapper.exportActivityStatistical(messageStatisticalVO);
        } else {
            messageStatistical = messageMapper.exportAllStatistical(messageStatisticalVO);
        }
        return messageStatistical;
    }


}
